package com.example.myfinalhomework;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class add extends AppCompatActivity {
    private static final String TAG = "add";
    TextView name,phone,bz;
    Button up;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tianjia);
        name=findViewById(R.id.addname);
        phone=findViewById(R.id.addphone);
        bz=findViewById(R.id.beizhu);
        up =findViewById(R.id.addbutton);
        Log.i(TAG,"1");
        up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String namea=name.getText().toString().trim();
                String phonea=phone.getText().toString().trim();
                String bza=bz.getText().toString().trim();
                Log.i(TAG,"2");

                if(namea.isEmpty()){
                    Toast.makeText(add.this, "怎么称呼？", Toast.LENGTH_SHORT).show();
                }else if(phonea.isEmpty()){
                    Toast.makeText(add.this, "手机号是什么", Toast.LENGTH_SHORT).show();
                }else if(bza.isEmpty()){
                    Toast.makeText(add.this, "给个备注亲", Toast.LENGTH_SHORT).show();
                }else{
                    TXmanager.add(namea,phonea,bza);
                    Log.i(TAG,"3");
                    Toast.makeText(add.this, "成功辣", Toast.LENGTH_SHORT).show();

                }

            }
        });
        Toolbar toolbar=findViewById(R.id.toolbar_add);
        this.setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1=new Intent(add.this, Main.class);
                Log.i(TAG,"4");
                startActivity(intent1);
            }
        });
    }
}
